<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>订单列表-WeAdmin Frame型后台管理系统-WeAdmin 1.0</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../css/font.css">
		<link rel="stylesheet" href="../../css/weadmin.css">
		<script src="../../lib/layui/layui.js" charset="utf-8"></script>
		<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
		<!--[if lt IE 9]>
	      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
	      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
	    <![endif]-->
	</head>

	<body>
		<div class="weadmin-nav">
			<span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">演员管理</a>
        <a><cite>演员列表</cite></a>
      </span>
			<a class="layui-btn layui-btn-sm" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
				<i class="layui-icon" style="line-height:30px">ဂ</i></a>
		</div>
		<div class="weadmin-block">
			<button class="layui-btn layui-btn-danger" onclick="getTemplate()"><!--<i class="layui-icon"></i>-->下载批量导入模板</button>
			<!--<button class="layui-btn" onclick=""><i class="layui-icon">上传文件批量导入</i></button>-->
			<button type="button" class="layui-btn" id="test3"><i class="layui-icon"></i>上传文件批量导入</button>
		</div>
		<div class="weadmin-body">
			<table class="layui-table" id="performerList" lay-filter="performer">

			</table>
			<script type="text/html" id="barDemo">
				<!--<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>-->
				<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
				<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
			</script>
		</div>
		<script src="../../lib/jquery-2.1.1/jquery.js"></script>
		<script src="../../js/admin.js"></script>
		<script>
			function getTemplate(){
				window.location.href="/performer/getTemplate"
			}
			layui.extend({
				admin: '{/}../../js/admin'
			});
			layui.use(['laydate', 'laypage', 'layer', 'table', 'carousel', 'upload', 'element', 'slider'], function() {
				var laydate = layui.laydate //日期
						, laypage = layui.laypage //分页
						, layer = layui.layer //弹层
						, table = layui.table //表格
						, upload = layui.upload //上传

				//指定允许上传的文件类型
				upload.render({
					elem: '#test3'
					,url: '/performer/listUpload' //改成您自己的上传接口
					,accept: 'file' //普通文件
					,exts: 'xlsx' //只允许上传压缩文件
					,done: function(res){
						if(res.code===0){
							layer.msg('上传成功');
							window.location.reload();
						}
					}
				});

				//执行一个 table 实例
				table.render({
					elem: '#performerList'
					, height: 500
					, url: '/performer/queryAllByLimit' //数据接口
					,method: 'post'
					, title: '演员表'
					, page: true //开启分页
					, toolbar: 'default' //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
					, totalRow: false //开启合计行
					, cols: [[ //表头
						{type: 'checkbox', fixed: 'left'}
						, {field: 'id', title: 'ID', width: 100, sort: true, fixed: 'left', totalRowText: '合计：'}
						, {field: 'name', title: '演员名', width: 200}
						, {field: 'mobile', title: '手机号', width: 200,  totalRow: true}
						, {field: 'createTime', title: '创建时间', width: 200,  totalRow: true}
						,{fixed: 'right', width: 165, align:'center', toolbar: '#barDemo'}
					]]
				});
				//监听头工具栏事件
				table.on('toolbar(performer)', function(obj){
					var checkStatus = table.checkStatus(obj.config.id)
							,data = checkStatus.data; //获取选中的数据
					switch(obj.event){
						case 'add':
							WeAdminShow('添加演员','./add.html',600,400)
							break;
						case 'update':
							if(data.length === 0){
								layer.msg('请选择一行');
							} else if(data.length > 1){
								layer.msg('只能同时编辑一个');
							} else {
								localStorage.setItem("performerId",checkStatus.data[0].id)
								console.log(checkStatus.data[0])
								localStorage.setItem("performer_name",checkStatus.data[0].name)
								localStorage.setItem("performer_mobile",checkStatus.data[0].mobile)
								WeAdminShow('编辑演员信息','./edit.html',600,400)

							}
							break;
						case 'delete':
							if(data.length === 0){
								layer.msg('请选择一行');
							} else {
								var ids=[]

								for(var i =0;i<data.length;i++){
									ids.push(data[i].id)
								}
								$.ajax({
									url: '/performer/deleteByIds',
									data:{
										"ids":ids
									},
									success(res){
										layer.msg("删除成功")
										window.location.reload();//修改成功后刷新父界面
									},
									error(){

									}
								})
							}
							break;
					};
				});

				//监听行工具事件
				table.on('tool(performer)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
					var data = obj.data //获得当前行数据
							,layEvent = obj.event; //获得 lay-event 对应的值
					if(layEvent === 'detail'){
						layer.msg('查看操作');
					} else if(layEvent === 'del'){
						layer.confirm('真的删除行么', function(index){
							console.log(obj.data.id,index)
							$.ajax({
								url: '/performer/delete',
								data:{
									"id":obj.data.id
								},
								success(res){
									obj.del(); //删除对应行（tr）的DOM结构
									layer.close(index);
								},
								error(){

								}
							})

						});
					} else if(layEvent === 'edit'){
						localStorage.setItem("performerId",data.id)
						localStorage.setItem("performer_name",data.name)
						localStorage.setItem("performer_mobile",data.mobile)
						WeAdminShow('编辑演员信息','./edit.html',600,400)
					}
				});
			});
		</script>
	</body>

</html>